package com.java.exer;

import java.util.*;

/**
 * 练习1：	对Poker对象，乱序添加到List中，并使用Collections 排序；
 * 先按照花色排序：黑红梅方，花色一致再按照点数排序。
 *
 * @author shkstart
 * @create 2021-01-18 17:03
 */
public class ListTest {
    public static void main(String[] args) {
        List l1 = new ArrayList();
        l1.add(new Poker(PokerType.BLACK_T, PokerPoint.P2));
        l1.add(new Poker(PokerType.RED_T, PokerPoint.P8));
        l1.add(new Poker(PokerType.FK, PokerPoint.P4));
        l1.add(new Poker(PokerType.MH, PokerPoint.P7));
        l1.add(new Poker(PokerType.FK, PokerPoint.P7));

        Collections.sort(l1, new Comparator<Poker>() {

            @Override
            public int compare(Poker o1, Poker o2) {
                if (o1 == null) {
                    return 1;
                }
                if (o2 == null) {
                    return -1;
                }
                if (o1.getType().getValue() > o2.getType().getValue()) {
                    return 1;
                } else if (o1.getType().getValue() == o2.getType().getValue()) {
                    if (o1.getNum().getVal() > o2.getNum().getVal()) {
                        return 1;
                    }
                }
                return -1;

            }
        });

        for (Object l : l1) {
            System.out.println(l);
        }


    }
}
